// ChildFrm.cpp : implementation of the CChildFrame class
//

#include "stdafx.h"
#include "SpriteTool.h"

#include "ChildFrm.h"
#include "LeftView.h"
#include "SpriteView.h"
#include "ImageView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChildFrame

IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)

BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
	//{{AFX_MSG_MAP(CChildFrame)
	ON_COMMAND(ID_NEW_FRAME, OnNewFrame)
	ON_COMMAND(ID_NEW_SPRITE, OnNewSprite)
	ON_COMMAND(ID_LOAD_IMAGES, OnLoadImages)
	ON_COMMAND(ID_DELETE, OnDelete)
	ON_COMMAND(ID_ZOOM_IN, OnZoomIn)
	ON_COMMAND(ID_ZOOM_OUT, OnZoomOut)
	ON_COMMAND(ID_FLIP_Y, OnFlipY)
	ON_COMMAND(ID_NEW_ACTION, OnNewAction)
	ON_COMMAND(ID_BUTTON_DELETE_IMG, OnButtonDeleteImg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChildFrame construction/destruction

CChildFrame::CChildFrame()
{
}

CChildFrame::~CChildFrame()
{
}

BOOL CChildFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
	CCreateContext* pContext)
{
	// create splitter window
	if (!m_wndSplitter.CreateStatic(this, 1, 3))
		return FALSE;

	if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(200, 200), pContext) ||
		!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CSpriteView), CSize(400, 400), pContext) ||
		!m_wndSplitter.CreateView(0, 2, RUNTIME_CLASS(CImageView), CSize(200, 200), pContext))
	{
		m_wndSplitter.DestroyWindow();
		return FALSE;
	}

	return TRUE;
}

BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CMDIChildWnd::PreCreateWindow(cs) )
		return FALSE;

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CChildFrame diagnostics

#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
	CMDIChildWnd::AssertValid();
}

void CChildFrame::Dump(CDumpContext& dc) const
{
	CMDIChildWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CChildFrame message handlers

CSpriteView* CChildFrame::GetSpriteView()
{
	return (CSpriteView*) m_wndSplitter.GetPane(0, 1);
}

CImageView* CChildFrame::GetImageView()
{
	return (CImageView*) m_wndSplitter.GetPane(0, 2);
}

CLeftView* CChildFrame::GetLeftView()
{
	return (CLeftView*) m_wndSplitter.GetPane(0, 0);
}

void CChildFrame::OnNewFrame() 
{
	CLeftView* pLeftView = GetLeftView();
	pLeftView->OnNewFrame();
}


void CChildFrame::OnNewAction() 
{
	CLeftView* pLeftView = GetLeftView();
	pLeftView->OnNewAction();
}

void CChildFrame::OnNewSprite() 
{
	CLeftView* pLeftView = GetLeftView();
	pLeftView->OnNewSprite();
}


void CChildFrame::OnLoadImages() 
{
	CImageView* pImageView = GetImageView();
	pImageView->OnLoadImages();
}

void CChildFrame::OnDelete() 
{
	CLeftView* pLeftView = GetLeftView();
	pLeftView->OnDelete();
	if(pLeftView->m_bDeleteSuccess)
	{
		CSpriteView* pView = GetSpriteView();
		pView->Invalidate();
	}
}

void CChildFrame::OnZoomIn() 
{
	CSpriteView* pView = GetSpriteView();
	pView->OnZoomIn();
}

void CChildFrame::OnZoomOut() 
{
	CSpriteView* pView = GetSpriteView();
	pView->OnZoomOut();
}

void CChildFrame::OnFlipY() 
{
	CView* pAct = GetActiveView();
	CSpriteView* pView = GetSpriteView();
	BOOL bFrame = pAct == pView ? TRUE : FALSE;
	pView->OnFlipY(bFrame);
}

void CChildFrame::OnButtonDeleteImg() 
{
	// TODO: Add your command handler code here
	
}
